;(async function () {
  const express = require("express")
  const db = require("./db/connectdb")
  const adminRouter = require("./routes/adminRouter")
  const loginRouter = require("./routes/loginRouter")
  const advRouter = require("./routes/advRouter")

  try {
    await db
    console.log("数据库连接成功")
    const app = express()

    app.use(express.json())
    app.use(express.static('./public'))
    app.use(adminRouter)
    app.use(loginRouter)
    app.use(advRouter) 

    app.listen(5001, (err) => {
      if (err) console.log("fail")
      else console.log("ok")
    })
  } catch (err) {
    console.log("数据库连接失败")
  }
})()
